package ${packageName}.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import ${packageName}.service.${table.className}Service;
import ${packageName}.entity.${table.className}Entity;

@Controller
@RequestMapping(value = "/${table.className?uncap_first}")
public class ${table.className}Controller extends BaseController{

	@Autowired
	private ${table.className}Service ${table.className?uncap_first}Service;

	/**
     * 主页
     */
    @RequestMapping(method=RequestMethod.GET)
    public String ${table.className?uncap_first}(ModelMap map){
        return ""; // TODO
    }

    /**
     * 列表查询
     * @return  Map<String,Object>
     */
    @ResponseBody
    @RequestMapping(value="/_search")
    public Map<String,Object> search(HttpServletRequest request){
        int pageNo = Integer.valueOf(request.getParameter("page"));
        int pageSize = Integer.valueOf(request.getParameter("rows"));
        SqlCriteria sqlCriteria = new SqlCriteria();
        Page<${table.className}Entity> page = ${table.className?uncap_first}Service.queryPage${table.className}(sqlCriteria, pageNo, pageSize);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("rows", page);
        map.put("total", page.getTotal());
        map.put("pageSize", page.getPageSize());
        return map;
    }

    /**
     * 编辑页面
     */
    @RequestMapping(value="/_edit",method=RequestMethod.GET)
    public String edit(){
        return "";// TODO
    }

    /**
     * 保存操作
     * @return  Map<String,Object>
     */
    @ResponseBody
    @RequestMapping(value="/_save",method=RequestMethod.POST)
    public Map<String,Object> save(HttpServletRequest request,${table.className}Entity ${table.className}){
        ${table.className?uncap_first}Service.save${table.className}(${table.className});
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("success", 1);
        return map;
    }


    /**
     * 删除操作
     * @return  Map<String,Object>
     */
    @ResponseBody
    @RequestMapping(value="/{id}",method=RequestMethod.DELETE)
    public Map<String,Object> delete(HttpServletRequest request,@PathVariable String id){
        ${table.className?uncap_first}Service.del${table.className}ById(id);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("success", 1);
        return map;
    }

    /**
     * 根据id获取
     * @return  SysSystemEntity
     */
    @ResponseBody
    @RequestMapping(value="/{id}",method=RequestMethod.GET)
    public ${table.className}Entity get(HttpServletRequest request,@PathVariable String id){
        ${table.className}Entity ${table.className?uncap_first} = ${table.className?uncap_first}Service.get${table.className}ById(id);
        return ${table.className?uncap_first};
    }
}